home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / xpipeman / actions.c next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.7 KB  |  192 lines

  1. /*
  2.  * actions.c  - Xpipeman
  3.  *
  4.  * Send Constructive comments, bug reports, etc. to either
  5.  *
  6.  *          JANET: pavern@uk.ac.man.cs
  7.  *
  8.  *  or      INER : pavern%cs.man.ac.uk@nsfnet-relay.ac.uk
  9.  *
  10.  * All other comments > /dev/null !!
  11.  * 
  12.  * Copyright 1991 Nigel Paver
  13.  * 
  14.  * Permission to use, copy, modify, distribute, and sell this software and its
  15.  * documentation for any purpose is hereby granted without fee, provided that
  16.  * the above copyright notice appear in all copies and that both that
  17.  * copyright notice and this permission notice appear in supporting
  18.  * documentation, and that the author's name not be used in advertising or
  19.  * publicity pertaining to distribution of the software without specific,
  20.  * written prior permission.  The author makes no representations about the
  21.  * suitability of this software for any purpose.  It is provided "as is"
  22.  * without express or implied warranty.
  23.  * 
  24.  * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
  25.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE 
  26.  * AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
  27.  * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
  28.  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
  29.  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  30.  * 
  31.  *
  32.  *
  33.  * Acknowledgements to Brian Warkentine (brian@sun.COM) for his xrobots
  34.  * program (copyright  1989) which I cannibalized to write this program
  35.  */
  36.  
  37.  
  38. #include <X11/X.h>
  39. #include <X11/Intrinsic.h>
  40. #include <X11/StringDefs.h>
  41. #include <math.h>
  42. #include "xpipeman.h"
  43.  
  44. /*----------------------------------------------------------------------*/
  45. /*ARGSUSED*/
  46. XtActionProc
  47. do_nothing_action(w,event,params,num_params)
  48.   Widget w;
  49.   XEvent *event;
  50.   String *params;
  51.   Cardinal *num_params;
  52. {
  53.   /* do nothing */
  54. }
  55.  
  56. /*----------------------------------------------------------------------*/
  57. /*ARGSUSED*/
  58. XtActionProc
  59. move_here_action(w,event,params,num_params)
  60.   Widget w;
  61.   XButtonEvent *event;
  62.   String *params;
  63.   Cardinal *num_params;
  64. {
  65.   /* called to move a block to a specific place - does NOT place it */
  66.   int tmp_block_x, tmp_block_y;
  67.  
  68.   if((!game_active) || buttons_disabled) return;
  69.  
  70.   tmp_block_x = coord_to_pos(event->x);
  71.   tmp_block_y = coord_to_pos(event->y);
  72.   if (can_go(tmp_block_x,tmp_block_y))
  73.     {
  74.       if ((block_x == MAXX-3) && ( block_y == MAXY-1)) /*special case */ 
  75.     {
  76.       pipe_board[MAXX-3][MAXY-1] = EMPTY; /* first move */
  77.           redraw_block(MAXX-3,MAXY-1);
  78.     }
  79.       last_block_x = block_x;
  80.       last_block_y = block_y;
  81.  
  82.       block_x = tmp_block_x;
  83.       block_y = tmp_block_y;
  84.       show_movement();
  85.     }
  86.   XFlush(display);
  87. }
  88.  
  89. /*----------------------------------------------------------------------*/
  90. /*ARGSUSED*/
  91. XtActionProc
  92. display_pixmap_action(w,event,params,num_params)
  93.   Widget w;
  94.   XEvent *event;
  95.   String *params;
  96.   Cardinal *num_params;
  97. {
  98.   if (!(game_active))
  99.      display_allpixmaps();
  100. }
  101. /*----------------------------------------------------------------------*/
  102. /*ARGSUSED*/
  103. XtActionProc
  104. fast_flow_action(w,event,params,num_params)
  105.   Widget w;
  106.   XEvent *event;
  107.   String *params;
  108.   Cardinal *num_params;
  109. {
  110.   if((!game_active) || buttons_disabled) return;
  111.    speed_up_flow(); 
  112. }
  113.  
  114. /*----------------------------------------------------------------------*/
  115.  
  116. /*ARGSUSED*/
  117. XtActionProc
  118. move_action(w,event,params,num_params)
  119.   Widget w;
  120.   XButtonEvent *event;
  121.   String *params;
  122.   Cardinal *num_params;
  123. {
  124. /* 
  125.  *  Called to move the block with the keyboard keys.
  126.  */
  127.  
  128.   int diff_x=0, diff_y=0;
  129.   
  130.   int  tmp_num_params;
  131.  
  132.   tmp_num_params= *num_params;
  133.  
  134.   if((!game_active) || buttons_disabled) return;
  135.  
  136.   while((tmp_num_params)--) {
  137.  
  138.     if(!strcmp("right",*(params+tmp_num_params)))    diff_x = 1;
  139.     if(!strcmp("left", *(params+tmp_num_params)))    diff_x = -1;
  140.     if(!strcmp("up",   *(params+tmp_num_params)))    diff_y = -1;
  141.     if(!strcmp("down", *(params+tmp_num_params)))    diff_y = 1;
  142.   }
  143.  
  144.   if( can_go(block_x+diff_x,block_y+diff_y) ) {
  145.     if ((block_x == MAXX-3) && ( block_y == MAXY-1)) /*special case */ 
  146.       {
  147.     pipe_board[MAXX-3][MAXY-1] = EMPTY; /* first move */
  148.         redraw_block(MAXX-3,MAXY-1);
  149.       }
  150.  
  151.     last_block_x = block_x;
  152.     last_block_y = block_y;
  153.  
  154.     block_x += diff_x;
  155.     block_y += diff_y;
  156.     show_movement();
  157.   }
  158.   XFlush(display);
  159. }
  160.  
  161.  
  162.  
  163. /*ARGSUSED*/
  164. XtActionProc
  165. place_action(w,event,params,num_params)
  166.   Widget w;
  167.   XButtonEvent *event;
  168.   String *params;
  169.   Cardinal *num_params;
  170. {
  171. /* 
  172.  Places a block 
  173.  */
  174.   int diff_x, diff_y;
  175.  
  176.   if((!game_active) || buttons_disabled) return;
  177.   if (!place_block()) XBell(XtDisplay(w),100);
  178. }
  179.  
  180.  
  181. /*ARGSUSED*/
  182. XtEventHandler
  183. pointer_moved(w, closure, event)
  184.   Widget w;
  185.   caddr_t closure;
  186.   XPointerMovedEvent *event;
  187. {
  188.   if(game_active) ;
  189.  
  190. }
  191.  
  192.